package cglib;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
import proxy.Iproducer;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class Client {
    public static void main(String[] args) {
        producer producer=new producer();
        final producer producer1=
                (cglib.producer) Enhancer.create(producer.getClass(),
                new MethodInterceptor() {
            @Override
            public Object intercept(Object o, Method method,
                                    Object[] objects,
                                    MethodProxy methodProxy) throws Throwable {
                if ("sale".equals(method.getName()))
                return method.invoke(producer,(float)objects[0]*0.8f);
                if ("after".equals(method.getName()))
                    return method.invoke(producer,
                            (float)objects[0]*0.01f);
                return method.invoke(producer,objects);
            }
        });
        producer1.zhon(5000);
    }
}
